package host.skiree.nettydemo.server.service.impl;

import host.skiree.nettydemo.message.GroupListResponseMessage;
import host.skiree.nettydemo.message.Message;
import host.skiree.nettydemo.server.dto.impl.RoomChannelImpl;
import host.skiree.nettydemo.server.service.MessageHandler;
import io.netty.channel.ChannelHandlerContext;

import java.util.HashSet;
import java.util.Set;

/**
 * @author anorak
 */
public class GroupList implements MessageHandler {
    @Override
    public void handleMessage(ChannelHandlerContext ctx, Message message) {
        Set<String> names = new HashSet<>();
        // 不能使用 .inverse().keySet() 来获取数据
        RoomChannelImpl.ROOM_CHANNEL_MAP.forEach((k , v) -> {
            names.add(k);
        });
        ctx.writeAndFlush(new GroupListResponseMessage(names));
    }
}
